<template>
  <div class="all">
    <div class="header">
      <input type="text" placeholder="输入商品名或粘贴宝贝标题搜索" />
      <i class="iconfont icon-icon-test"></i>
      <div>消息</div>
      <i class="iconfont icon-xiaoxi"></i>
      <ul>
        <li>精选</li>
        <li @click="getRooter">美食</li>
        <li>居家日用</li>
        <li>女装</li>
        <li>美妆</li>
        <li>数码家电</li>
      </ul>
      <i class="iconfont icon-daohang"></i>
    </div>
    <div class="null"></div>
    <pageFooter />
    <div class="main">
      <div v-if="this.picture.length == 0">loading...</div>
      <van-swipe
        v-else
        class="my-swipe"
        :autoplay="3000"
        indicator-color="white"
      >
        <van-swipe-item v-for="item in picture" :key="item.id">
          <img v-lazy="item.pic" alt="" />
        </van-swipe-item>
      </van-swipe>
      <div class="list">
        <ul>
          <li v-for="item in goods" :key="item.name">
            <img v-lazy="item.address" alt="" @click="setRouter" />
            <span>{{ item.name }}</span>
          </li>
        </ul>
      </div>
      <div class="middle">
        <img
          src="https://img.alicdn.com/imgextra/i3/2053469401/O1CN011wdOkj2JJhy7TkPFo_!!2053469401.png"
          alt=""
        />
        <van-swipe
          style="height: 80px"
          :vertical="true"
          :autoplay="3000"
          :show-indicators="false"
        >
          <van-swipe-item v-for="item in loop" :key="item.name">
            <p>
              <span>{{ item.tag }}</span>
              {{ item.name | mysub(11) }}
            </p>
          </van-swipe-item>
        </van-swipe>
      </div>
      <div class="One">
        <div>
          <img
            src="https://img.alicdn.com/imgextra/i4/2053469401/O1CN01CJLHxw2JJi6OTMPAF_!!2053469401.gif"
            alt=""
          />
        </div>
        <ul>
          <li>
            <img
              src="https://img.alicdn.com/imgextra/i2/2053469401/O1CN01hz5nHP2JJi6P97A6h_!!2053469401.png"
              alt=""
            />
          </li>
          <li>
            <img
              src="https://img.alicdn.com/imgextra/i4/2053469401/O1CN01wbjjZd2JJi6K05wF6_!!2053469401.png"
              alt=""
            />
          </li>
          <li>
            <img
              src="https://img.alicdn.com/imgextra/i1/2053469401/O1CN01SGPY3y2JJi6aQ8I9k_!!2053469401.png"
              alt=""
            />
          </li>
          <li>
            <img
              src="https://img.alicdn.com/imgextra/i3/2053469401/O1CN01CYDYiR2JJi6aQARBZ_!!2053469401.png"
              alt=""
            />
          </li>
        </ul>
      </div>

      <div class="module">
        <div class="showList">
          <h3 class="title">咚咚抢</h3>
          <span class="clock">整点特惠开抢</span>
          <span class="qianging">正在抢</span>
        </div>
      </div>

      <div class="session">
        <!-- Swiper -->
        <div v-if="infoSession == null">loading</div>
        <session class="clother" v-else :data="infoSession"> </session>
      </div>

      <div class="tab">
        <div v-if="info.length == 0">loading</div>
        <myswiper v-else :data="info[currentIndex]">
          <template #action="row">
            <img v-lazy="row.item.pic" alt="" style="width: 200px" />
            <span style="font-size: 30px; color: red">{{
              "￥" + row.item.price
            }}</span>
            <del style="color: gray">{{ row.item.orginPrice }}</del>
            <div></div>
          </template>
        </myswiper>
      </div>

      <div class="phone">
        <div class="title">
          <h3>大家都在领</h3>
        </div>
        <div class="today">
          <span class="first">491,980</span>
          <span class="second">今日实时领券</span>
        </div>
      </div>
      <div class="picture">
        <div v-if="mold.length == 0">loading</div>
        <today v-else :data="mold"></today>
      </div>

      <div class="search">
        <div>
          <span>发现</span>
          <p>推荐好货</p>
        </div>
        <div class="goods"></div>
        <div>
          <span>精选</span>
          <p>猜你喜欢</p>
        </div>
      </div>
      <i id="scroll" @click="scrollToTop()" class="iconfont icon-xiangshangjiantou1">
      </i>
    </div>

    <div class="footer">
      <recommendList :data="footer"></recommendList>
    </div>
  </div>
</template>

<script>
import "@/assets/iconfont/iconfont.css";
import {
  getListData,
  getLoopData,
  getUpData,
  getTimeData,
  getPhoneData,
  getNumber,
} from "@/api/show";
import "@/assets/css/reset.css";
import session from "@/components/session/session.vue";
import myswiper from "@/components/myswiper/myswiper.vue";
import today from "@/components/today/today.vue";
import pageFooter from "@/components/common/pageFooter";
import recommendList from "@/views/recommendList";
export default {
  components: {
    session,
    myswiper,
    today,
    pageFooter,
    recommendList,
  },
  data() {
    return {
      picture: [],
      goods: "",
      loop: "",
      time: [],
      info: [],
      infoSession: [],
      num: "",
      currentIndex: 0,
      mold: [],
      footer: [],
      isFixed: false,
    };
  },
  methods: {
    getRooter() {
      this.$router.push("/list");
    },
    setRouter() {
      this.$router.push("/discount");
    },
    scrollToTop() {
      let scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
      if (scrollTop > 0) {
        window.scrollTo({
          left: 0,
          top: 0,
          behavior: "smooth",
        });
      }
    },

    handleScroll(el) {
      let topBtn = document.getElementById("scroll");
      let scrollTop =
        window.pageYOffset ||
        document.documentElement.scrollTop ||
        document.body.scrollTop;
        //获取窗口的外部高度(包括工具栏和滚动条)
      let browserHeight = window.outerHeight;
      if (scrollTop > browserHeight) {
        topBtn.style.display = "block";
      } else {
        topBtn.style.display = "none";
      }
    },
  },

  created() {
    this.$event.$on("sumPage", (item, index) => {
      this.num = item;
      console.log(index);
      this.currentIndex = index;
    });
  },
  async mounted() {
    let ret = await getLoopData();
    let line = await getListData();
    let up = await getUpData();
    let tData = await getTimeData();
    let phone = await getPhoneData();
    let number = await getNumber();
    // console.log(number.data.list)
    this.footer = number.data.list;
    // console.log(this.footer);
    this.mold = phone.data.config.list;
    // console.log(this.mold)

    this.picture = ret.data.config;

    this.goods = line.data.config.data;
    this.loop = up.data.config.list;
    this.time = tData.data.ddqSessions;

    this.infoSession = this.time;
     console.log(this.infoSession)

    this.time.forEach((item, index) => {
      this.info[index] = item.ddqGoodsList;
    });

    window.addEventListener("scroll", this.handleScroll);
  },
  destroyed() {
    window.removeEventListener("scroll", this.handleScroll);
  },
};
</script>

<style lang="scss" scoped>
html {
  height: 100%;
  background-color: #f6f6f6;
}
body {
  font-size: 14px;
  //  background-color: #f6f6f6;
}
.all {
  height: 4000px;
  background-color: #f6f6f6;
}
.header {
  width: 100%;
  position: fixed;
  left: 0;
  top: 0;
  z-index: 10000;
  height: 80px;
  border-color: rgb(92, 17, 129);
  background: rgb(92, 17, 129);
  input {
    width: 75%;
    padding-left: 10%;
    flex: 1;
    height: 30px;
    background: #fff;
    border-radius: 0.4rem;
    margin-left: 0.2rem;
    display: flex;
    align-items: center;
    margin-top: 10px;
  }
  i {
    position: absolute;
  }
  > div {
    position: absolute;
    top: 35px;
    right: 18px;
    color: white;
    font-size: 10px;
  }
  ul {
    width: 100%;
    display: flex;
    margin-top: 15px;
    li {
      margin-right: 8px;
      padding-left: 8px;
      justify-content: space-between;
      align-items: center;
      color: white;
      font-size: 15px;
    }
  }
}

.icon-icon-test {
  top: 11px;
  left: 15px;
  color: #999;
  font-size: 0.8rem;
}
.icon-xiaoxi {
  color: white;
  position: absolute;
  top: 10px;
  right: 18px;
  font-size: 0.6rem;
}
.icon-daohang {
  font-size: 0.5rem;
  color: white;
  position: absolute;
  top: 57px;
  right: 13px;
}
.null {
  height: 200px;
  border-color: rgb(92, 17, 129);
  background: rgb(92, 17, 129);
  border-radius: 15%;
}
.main {
  position: absolute;
  width: 94%;
  margin-left: 3%;
  top: 90px;
  border-radius: 0.3rem;
  z-index: 100;
}
.my-swipe .van-swipe-item {
  color: #fff;
  font-size: 20px;
  line-height: 100px;
  text-align: center;
  background-color: #39a9ed;
  height: 150px;
  border-radius: 0.3rem;
  overflow: hidden;
  > img {
    width: 100%;
    height: 100%;
    border-radius: 0.3rem;
  }
}
.list {
  width: 100%;
  height: 150px;
  display: flex;
  box-sizing: content-box;
  margin-top: 15px;
  background: white;
  // margin-left: 1%;
  border-bottom: 2px solid gainsboro;
  border-radius: 0.3rem 0.3rem 0 0;
  ul {
    display: flex;
    box-sizing: border-box;
    overflow: hidden;
    flex-wrap: wrap;
    justify-content: flex-start;
    li {
      min-width: 16%;
      margin-bottom: 1.3333vw;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: space-evenly;
      img {
        width: 13.33vw;
        height: 13.33vw;
        border: 0;
        vertical-align: middle;
      }
    }
  }
}
.middle {
  width: 100%;
  margin-top: 2px;
  background: white;
  display: flex;
  justify-content: flex-start;
  align-items: center;
  img {
    margin-left: 10px;
    margin-right: 10px;
  }
  p {
    font-size: 15px;
    line-height: 40px;
    text-align: center;
    span {
      width: 50px;
      height: 40px;
      background: orangered;
      border-radius: 15px;
      color: white;
    }
  }
}
.One {
  margin-top: 10px;
  width: 100%;
  > div {
    > img {
      width: 100%;
    }
  }
  ul {
    width: 100%;
    margin-top: 5px;
    display: flex;
    // flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    flex-wrap: wrap;
    li {
      width: 48%;
      margin: 3px;
      img {
        width: 100%;
      }
    }
  }
}

.module {
  width: 100%;
  margin-top: 10px;
  background: white;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-radius: 20px 20px 0 0;
  .showList {
    display: flex;
    align-items: center;
    margin-bottom: 0.2rem;
    width: 100%;
    overflow: hidden;
    z-index: 1000;
    .title {
      font-size: 18px;
      margin-left: 20px;
      margin-top: 10px;
    }
    .clock {
      margin-left: 14px;
      color: gainsboro;
      margin-top: 12px;
    }
    .qianging {
      margin-top: 13px;
      margin-left: 130px;
      color: orangered;
    }
  }
}
.session {
  background: white;
}
.tab {
  background: white;
  width: 100%;
  span {
    margin-left: 10px;
    margin-right: 10px;
  }
}

.phone {
  background: white;
  width: 100%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  height: 60px;
  border-radius: 20px 20px 0 0;
  .title {
    font-size: 20px;
    margin-left: 10px;
  }
  .first {
    font-size: 15px;
    color: red;
    margin-right: 15px;
  }
  .second {
    margin-right: 20px;
  }
}
.picture {
  width: 100%;
  background: white;
  border-radius: 0 0 20px 20px;
}
.search {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 10px;
  div {
    font-size: 20px;
    margin-left: 10px;
    margin-right: 10px;
    span {
      display: inline-block;
      width: 80px;
      height: 40px;
      //  background: chartreuse;
      text-align: center;
      line-height: 40px;
      margin-left: 20px;
    }
    p {
      width: 120px;
      text-align: center;
      line-height: 40px;
      height: 40px;
      background: darkorange;
      color: white;
      border-radius: 20px;
    }
  }
}
.goods {
  width: 2px;
  height: 40px;
  background: gray;
  display: inline-block;
  margin-top: 31px;
  vertical-align: top;
  margin-right: 29px;
  margin-left: 30px;
}
#scroll {
  position: fixed;
  top: 550px;
  right: 20px;
  background:rgba(0,0,0,.6);
  font-size: 34px;
  z-index: 1000;
  display: none;
  border-radius: 100%;
  color: white;
}
.footer {
  position: absolute;
  top: 1300px;
  padding-bottom: 40px;
}
</style>